
package cn.gz3c.uitest;

import android.annotation.SuppressLint;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.Window;
import android.view.WindowManager.LayoutParams;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider;
import androidx.navigation.NavController;
import androidx.navigation.NavGraph;
import androidx.navigation.NavGraphNavigator;
import androidx.navigation.NavigatorProvider;
import androidx.navigation.fragment.FragmentNavigator.Destination;
import androidx.navigation.fragment.NavHostFragment;

import com.huawei.hms.audioeditor.sdk.HAETimeLine;
import com.huawei.hms.audioeditor.sdk.HuaweiAudioEditor;
import com.huawei.hms.audioeditor.sdk.asset.HAEAsset;
import com.huawei.hms.audioeditor.sdk.asset.HAEAudioAsset;
import com.huawei.hms.audioeditor.sdk.engine.audio.thumbnail.ThumbnailManager;
import com.huawei.hms.audioeditor.sdk.hianalytics.impl.HianalyticsEvent10001;
import com.huawei.hms.audioeditor.sdk.hianalytics.info.Event10001Info;
import com.huawei.hms.audioeditor.sdk.history.HistoryManager;
import com.huawei.hms.audioeditor.sdk.lane.HAEAudioLane;
import com.huawei.hms.audioeditor.sdk.lane.HAEEffectLane;
import com.huawei.hms.audioeditor.sdk.store.file.bean.project.HAEDataProject;
import com.huawei.hms.audioeditor.sdk.util.FileUtil;
import com.huawei.hms.audioeditor.sdk.util.SmartLog;
import com.huawei.hms.audioeditor.ui.R.id;
import com.huawei.hms.audioeditor.ui.R.layout;
import com.huawei.hms.audioeditor.ui.R.string;
import com.huawei.hms.audioeditor.ui.api.AudioInfo;
import com.huawei.hms.audioeditor.ui.common.BaseActivity;
import com.huawei.hms.audioeditor.ui.common.listener.OnClickRepeatedListener;
import com.huawei.hms.audioeditor.ui.common.widget.dialog.ConfirmDialog;
import com.huawei.hms.audioeditor.ui.common.widget.dialog.LoadingIndicatorView;
import com.huawei.hms.audioeditor.ui.common.widget.dialog.a;
import com.huawei.hms.audioeditor.ui.editor.export.AudioExportActivity;
import com.huawei.hms.audioeditor.ui.editor.panel.fragments.AudioAccompanimentSeparationPanelFragment;
import com.huawei.hms.audioeditor.ui.editor.panel.fragments.AudioBalancePanelFragment;
import com.huawei.hms.audioeditor.ui.editor.panel.fragments.AudioCopyPanelFragment;
import com.huawei.hms.audioeditor.ui.editor.panel.fragments.AudioEnvironmentPanelFragment;
import com.huawei.hms.audioeditor.ui.editor.panel.fragments.AudioFadeInOutPanelFragment;
import com.huawei.hms.audioeditor.ui.editor.panel.fragments.AudioMaterialPanelFragment;
import com.huawei.hms.audioeditor.ui.editor.panel.fragments.AudioMaterialSearchPanelFragment;
import com.huawei.hms.audioeditor.ui.editor.panel.fragments.AudioMusicStylePanelFragment;
import com.huawei.hms.audioeditor.ui.editor.panel.fragments.AudioRecorderPanelFragment;
import com.huawei.hms.audioeditor.ui.editor.panel.fragments.AudioSoundGroundPanelFragment;
import com.huawei.hms.audioeditor.ui.editor.panel.fragments.AudioSoundSeparationPanelFragment;
import com.huawei.hms.audioeditor.ui.editor.panel.fragments.AudioSpaceRenderPanelFragment;
import com.huawei.hms.audioeditor.ui.editor.panel.fragments.AudioTextToSpeechPanelFragment;
import com.huawei.hms.audioeditor.ui.editor.panel.fragments.AudioVoiceChangeFragment;
import com.huawei.hms.audioeditor.ui.editor.panel.fragments.AudioVolumePanelFragment;
import com.huawei.hms.audioeditor.ui.editor.panel.fragments.AudioVolumeSpeedPanelFragment;
import com.huawei.hms.audioeditor.ui.editor.panel.fragments.SoundEffectPanelFragment;
import com.huawei.hms.audioeditor.ui.editor.trackview.fragment.EditPreviewFragment;

import java.io.File;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.CountDownLatch;

import cn.gz3c.uitest.viewmodel.ClipViewModel;
import cn.gz3c.uitest.viewmodel.EditPreviewViewModel;
import cn.gz3c.uitest.viewmodel.MenuHelper;
import cn.gz3c.uitest.viewmodel.MenuViewModel;

public class AudioClipsActivity extends BaseActivity {
    private ClipViewModel clipViewModel;
    private EditPreviewViewModel editPreviewViewModel;
    private EditPreviewFragment d;
    private MenuViewModel menuViewModel;
    private HuaweiAudioEditor f;
    private HAETimeLine g;
    private HAEAudioLane h;
    private ImageView i;
    private TextView j;
    private LoadingIndicatorView k;
    private AlertDialog l;
    private CountDownLatch m;
    private Handler n;
    private NavController o;
    private volatile long p = 0L;
    private long q;
    private long r;
    private int s = 0;
    private final boolean t = false;
    private String u = "";
    private ArrayList<AudioInfo> v;
    private boolean w = false;
    private boolean x = false;
    private ConstraintLayout y;
    private a z;
    private boolean A = false;
    private LoadingIndicatorView B;

    public AudioClipsActivity() {
    }

    private void h() {
        super.mContext = this;
        this.n = new Handler();
        this.q = System.currentTimeMillis();
        boolean var1 = true;
        Intent var2;
        if ((var2 = this.getIntent()) != null) {
            label65:
            {
                Intent var10000 = var2;
                AudioClipsActivity var10001 = this;
                Intent var10002 = var2;
                String var10003 = "select_result";

                Exception var9;
                label66:
                {
                    boolean var11;
                    try {
                        var10001.v = var10002.getParcelableArrayListExtra(var10003);
                    } catch (Exception var7) {
                        var9 = var7;
                        var11 = false;
                        break label66;
                    }

                    String var13 = "draftId";

                    boolean var10;
                    try {
                        var10 = com.huawei.hms.audioeditor.ui.common.utils.a.a(var10000.getStringExtra(var13));
                    } catch (Exception var6) {
                        var9 = var6;
                        break label66;
                    }

                    AudioClipsActivity var12;
                    Intent var14;
                    String var15;
                    if (!var10) {
                        var12 = this;
                        var14 = var2;
                        var15 = "draftId";

                        try {
                            var12.u = var14.getStringExtra(var15);
                        } catch (Exception var5) {
                            var9 = var5;
                            break label66;
                        }
                    }

                    var12 = this;
                    var14 = var2;
                    var15 = "saveDraft";

                    try {
                        var12.w = var14.getBooleanExtra(var15, false);
                        break label65;
                    } catch (Exception var4) {
                        var9 = var4;
                    }
                }

                Exception var3 = var9;
                SmartLog.e("AudioClipsFragment", com.huawei.hms.audioeditor.ui.p.a.a("getExtra Fail : ").append(var3.getMessage()).toString());
            }
        }

        SmartLog.i("AudioClipsFragment", com.huawei.hms.audioeditor.ui.p.a.a("get Intent projectId is ").append(this.u).toString());
        this.a(var2);
        if (TextUtils.isEmpty(this.u)) {
            this.f = HuaweiAudioEditor.create(super.mContext);
        } else {
            var1 = false;
            this.f = HuaweiAudioEditor.create(super.mContext, this.u);
        }

        this.f.initEnvironment();
        this.g = this.f.getTimeLine();
        this.clipViewModel.a(this.f);
        com.huawei.hms.audioeditor.ui.p.b.b().a(this.g);
        this.editPreviewViewModel.a(this.g);
        this.editPreviewViewModel.a(this.f);
        this.menuViewModel.a(this.editPreviewViewModel);
        this.menuViewModel.a(this.clipViewModel);
        if (!var1) {
            HAEDataProject var8 = this.f.getProjectData(this.u);
            this.f.restoreProject(var8);
        }

        this.h = this.g.getAudioLane(0);
        this.editPreviewViewModel.a(this.h);
        if (var1 && this.v == null) {
            SmartLog.d("AudioClipsFragment", "no audios,need import.");
            this.x = false;
            this.j.setEnabled(false);
        } else {
            this.b(var2);
        }

    }

    private void a(Intent var1) {
        String var2;
        ArrayList var5;
        label34:
        {
            if (var1 != null) {
                Intent var10000 = var1;
                String var10001 = "audio_path_list";

                try {
                    var5 = var10000.getStringArrayListExtra(var10001);
                    break label34;
                } catch (Exception var4) {
                    SmartLog.e("AudioClipsFragment", com.huawei.hms.audioeditor.ui.p.a.a("getCpDataList : ").append(var4.getMessage()).toString());
                }
            }
            var5 = null;
        }

        if (var5 != null) {
            this.v = new ArrayList();
            Iterator var6 = var5.iterator();

            while (var6.hasNext()) {
                var2 = (String) var6.next();
                AudioInfo var3;
                var3 = new AudioInfo(var2);
                if ((new File(var2)).exists()) {
                    var3.setAudioName(FileUtil.getFileName(var2) + "." + FileUtil.getFileExtensionName(var2));
                    this.v.add(var3);
                }
            }

            if (this.v.size() == 0) {
                com.huawei.hms.audioeditor.ui.common.utils.i.a(this, this.getResources().getString(string.failed_import_file), 0).a();
            }
        }

    }

    private void b(Intent var1) {
        ArrayList var6;
        if (var1 == null) {
            ArrayList var9 = var6 = new ArrayList();
//            var9.<init>();
            this.a((List) var9);
            if (var6.size() == 0) {
                this.finish();
            }

        } else {
            AudioClipsActivity var10000 = this;
            Intent var10001 = var1;
            String var10002 = "select_result";

            try {
                var10000.v = var10001.getParcelableArrayListExtra(var10002);
            } catch (Exception var5) {
                SmartLog.e("AudioClipsFragment", com.huawei.hms.audioeditor.ui.p.a.a("reloadUIData : ").append(var5.getMessage()).toString());
            }

            this.a(var1);
            var6 = new ArrayList();
            int var2 = this.e();
            if (this.v != null) {
                for (int var3 = 0; var3 < this.v.size() && var3 < var2; ++var3) {
                    AudioInfo var4 = (AudioInfo) this.v.get(var3);
                    if (ThumbnailManager.getInstance().isValidAudio(var4.getAudioPath())) {
                        var6.add(var4.getAudioPath());
                    } else {
                        com.huawei.hms.audioeditor.ui.common.utils.i.a(this, this.getResources().getString(string.unsupported_audio), 0).a();
                    }
                }
            } else {
                this.a((List) var6);
            }

            if (var6.size() != 0) {
                this.k.show();
                AlertDialog var7;
                if ((var7 = this.l) != null) {
                    var7.cancel();
                }

                this.l = (new Builder(super.mContext)).setCancelable(false).create();
                Window var8 = this.l.getWindow();
                LayoutParams var10 = var8.getAttributes();
                var10.alpha = 0.0F;
                var8.setAttributes(var10);
                this.l.show();
                (new Thread(() -> {
//                    AudioClipsActivity var10000 = this;
//                    AudioClipsActivity var10001 = this;
//                    AudioClipsActivity var10002 = this;
                    this.m = new CountDownLatch(var6.size());
                    CountDownLatch countDownLatch = this.m;
                    ThumbnailManager.getInstance().generateWaveThumbnailCache(var6, countDownLatch);

                    label49:
                    {
                        InterruptedException interruptedException;
                        label53:
                        {
                            boolean var9;
                            try {
                                m.await();
                            } catch (InterruptedException var4) {
                                interruptedException = var4;
                                var9 = false;
                                break label53;
                            }

                            String tag = "AudioClipsFragment";
                            String var10003 = "all the audio data load complete";

                            SmartLog.i(tag, var10003);
                            var10000.runOnUiThread(() -> {
                                this.k.hide();
                                AlertDialog alertDialog;
                                if ((alertDialog = this.l) != null) {
                                    alertDialog.cancel();
                                    this.l = null;
                                }

                            });
                            break label49;
                        }

                        InterruptedException var5 = interruptedException;
                        SmartLog.e("AudioClipsFragment", com.huawei.hms.audioeditor.ui.p.a.a("got exception ").append(var5.getMessage()).toString());
                    }

                    if (this.getApplicationContext() != null) {
                        if (this.v != null) {
                            this.f();
                        } else {
                            Iterator var6x = this.g.getAllAudioLane().iterator();

                            while (var6x.hasNext()) {
                                ((HAEAudioLane) var6x.next()).removeAllAssets();
                            }

                            var6x = this.g.getAllEffectLane().iterator();

                            while (var6x.hasNext()) {
                                ((HAEEffectLane) var6x.next()).removeAllEffects();
                            }

                            HAEDataProject haeDataProject = this.f.getProjectData(this.u);
                            this.f.restoreProject(haeDataProject);
                            HistoryManager.getInstance().clearHistory();
                        }

                        this.editPreviewViewModel.M();
                        this.editPreviewViewModel.K();
                        this.editPreviewViewModel.J();
                    }
                })).start();
            }
        }
    }

    private void f() {
        int var1 = Math.min(this.e(), 100 - this.editPreviewViewModel.b().size());

        for (int var2 = 0; var2 < this.v.size() && var2 < var1; ++var2) {
            AudioInfo var3;
            if (FileUtil.isContainsAudio((var3 = (AudioInfo) this.v.get(var2)).getAudioPath())) {
                this.h = com.huawei.hms.audioeditor.ui.p.b.b().a();
                HAEAudioAsset var4;
                if ((var4 = this.h.appendAudioAsset(var3.getAudioPath(), this.g.getCurrentTime())) != null && (new File(var4.getPath())).exists()) {
                    var4.setAudioName(var3.getAudioName());
                    Event10001Info var5;
                    Event10001Info var10000 = var5 = new Event10001Info();
//                    var5.<init>();
                    var5.setAudioFormat(FileUtil.getFileExtensionName(var3.getAudioPath()));
                    var5.setSampleRate(var4.getSampleRate());
                    var5.setChannelCount(var4.getChannelCount());
                    var10000.setBitDepth(var4.getBitDepth());
                    var10000.setResultDetail("0");
                    HianalyticsEvent10001.postEvent(var10000);
                } else {
                    this.runOnUiThread(() -> {
                        com.huawei.hms.audioeditor.ui.common.utils.i.a(this, this.getResources().getString(string.tip_error_parses)).a();
                    });
                    SmartLog.e("AudioClipsFragment", "append to timeline failed");
                }
            }
        }

    }

    private int e() {
        byte var3 = 10;
        int var1 = 0;

        for (HAEAudioLane haeAudioLane : this.editPreviewViewModel.G().getAllAudioLane()) {
            if (haeAudioLane.getAssets().size() > 0) {
                ++var1;
            }
        }

        int var4;
        if ((var4 = var3 - var1) > 5) {
            var4 = 5;
        }

        return var4;
    }

    private void a(List<String> var1) {
        HuaweiAudioEditor var2;
        if ((var2 = this.f) != null && var2.getTimeLine() != null && var1 != null) {
            List var4;
            if ((var4 = this.f.getTimeLine().getAllAudioLane()).size() != 0) {
                Iterator var5 = var4.iterator();

                while (true) {
                    List var6;
                    do {
                        do {
                            if (!var5.hasNext()) {
                                return;
                            }
                        } while ((var6 = ((HAEAudioLane) var5.next()).getAssets()) == null);
                    } while (var6.size() == 0);

                    Iterator var7 = var6.iterator();

                    while (var7.hasNext()) {
                        HAEAsset var3;
                        if (!var1.contains((var3 = (HAEAsset) var7.next()).getPath())) {
                            var1.add(var3.getPath());
                        }
                    }
                }
            }
        }
    }

    private void g() {
        this.i.setOnClickListener(new OnClickRepeatedListener(v -> onBackPressed(), 100L));
        this.getOnBackPressedDispatcher().addCallback(new OnBackPressedCallback(true) {
            @Override
            public void handleOnBackPressed() {
                onBackPressed();
            }
        });
        this.j.setOnClickListener(new OnClickRepeatedListener((var1) -> {
            if (this.x) {
                this.startActivity(new Intent(this, AudioExportActivity.class));
            }

        }));
        this.editPreviewViewModel.d().observe(this, new Observer<Long>() {
            @Override
            public void onChanged(Long aLong) {

            }
        });
        this.clipViewModel.b().observe(this, (var1) -> {
            if (var1 == -1L) {
                this.p = 0L;
            } else {
                this.p = var1;
                if (this.t) {
                    this.d.a(this.p);
                }

            }
        });
        this.clipViewModel.d().observe(this, new Observer<Boolean>() {
            @Override
            public void onChanged(Boolean aBoolean) {

            }
        });
        this.clipViewModel.e().observe(this, new Observer<Boolean>() {
            @Override
            public void onChanged(Boolean aBoolean) {

            }
        });
        this.editPreviewViewModel.s().observe(this, (var1) -> {
            this.s = var1;
            this.a(this.s);
        });
        this.editPreviewViewModel.e().observe(this, new Observer<List<HAEAudioAsset>>() {
            @Override
            public void onChanged(List<HAEAudioAsset> haeAudioAssets) {

            }
        });
        this.editPreviewViewModel.r().observe(this, new Observer<Boolean>() {
            @Override
            public void onChanged(Boolean aBoolean) {

            }
        });
        this.editPreviewViewModel.B().observe(this, new Observer<Integer>() {
            @Override
            public void onChanged(Integer integer) {

            }
        });
    }

    private void k() {
        if (this.o.getCurrentDestination().getId() == id.audioEditMenuFragment && this.menuViewModel.ldMenuType.getValue() == MenuHelper.MenuType.a) {
            ArrayList var1;
            ArrayList var10001 = var1 = new ArrayList<>();
//            var10001.<init>();
            this.a(var10001);
            if (var1.size() > 0 && this.w) {
                this.f.saveProject();
            } else {
                ThumbnailManager.getInstance().cleanWaveThumbnailCache(var1);
            }

            if (!this.w) {
                HuaweiAudioEditor.deleteProject(this.f.getProjectId());
            }

            HuaweiAudioEditor var2;
            if ((var2 = this.f) != null) {
                var2.stopEditor();
            }

            if (//!a &&
                    this.f == null) {
                throw new AssertionError();
            }

            this.finish();
        } else {
            super.onBackPressed();
        }

    }

    @SuppressLint("ClickableViewAccessibility")
    private void b(boolean var1) {
        a var2;
        if ((var2 = this.z) == null || !var2.isShowing()) {
            this.z = new a(this, layout.text_to_audio_pop_window, view -> {
                B = view.findViewById(id.indicator);
                B.show();
            });
            if (!var1) {
                this.z.setTouchInterceptor((var0, var1x) -> true);
            }

            this.z.showAtLocation(this.y, 80, 20, 0);
        }

    }

    public void onCreate(Bundle var1) {
        super.onCreate(var1);
        this.setContentView(layout.fragment_audio_clips);
        if (var1 != null) {
            this.p = var1.getLong("mCurrentTime");
        }

        AudioClipsActivity var10000 = this;
        AudioClipsActivity var10001 = this;
        AudioClipsActivity var10002 = this;
        com.huawei.hms.audioeditor.ui.common.a.a().a(super.mContext);
        this.y = this.findViewById(id.cl_father);
        this.i = this.findViewById(id.iv_back);
        this.j = this.findViewById(id.tv_save);
        String var4 = this.j.getText().toString().toUpperCase(Locale.ROOT);
        this.j.setText(var4);
        this.d = (EditPreviewFragment) this.getSupportFragmentManager().findFragmentById(id.id_edit_play_fragment);
        this.clipViewModel = (new ViewModelProvider(this, super.mFactory)).get(ClipViewModel.class);
        this.editPreviewViewModel = (new ViewModelProvider(this, super.mFactory)).get(EditPreviewViewModel.class);
        this.menuViewModel = (new ViewModelProvider(this)).get(MenuViewModel.class);
        this.k = this.findViewById(id.loading_view);
        Fragment var5;
        this.o = NavHostFragment.findNavController(var5 = this.getSupportFragmentManager().findFragmentById(id.audio_menu_item_fragment));
        com.huawei.hms.audioeditor.ui.a var2;
        var2 = new com.huawei.hms.audioeditor.ui.a(this, var5.getChildFragmentManager(), var5.getId());
        NavigatorProvider var3;
        (var3 = this.o.getNavigatorProvider()).addNavigator(var2);
        NavGraph var6;
        NavGraph var10003 = var6 = new NavGraph(new NavGraphNavigator(var3));
//        Destination var10039 = var2.createDestination();
//        com.huawei.hms.audioeditor.ui.p.a.a(var10039, id.audioEditMenuFragment, AudioEditMenuFragment.class, "AudioEditMenuFragment");
//        var6.addDestination(var10039);
        Destination var10037 = var2.createDestination();
        com.huawei.hms.audioeditor.ui.p.a.a(var10037, id.audioRecorderPanelFragment, AudioRecorderPanelFragment.class, "AudioRecorderPanelFragment");
        var10037.putAction(id.action_audioEditMenuFragment_to_audioRecorderPanelFragment, id.audioRecorderPanelFragment);
        var6.addDestination(var10037);
        Destination var10035 = var2.createDestination();
        com.huawei.hms.audioeditor.ui.p.a.a(var10035, id.audioFadeInOutPanelFragment, AudioFadeInOutPanelFragment.class, "AudioFadeInOutPanelFragment");
        var10035.putAction(id.action_audioEditMenuFragment_to_audioFadeInOutPanelFragment, id.audioFadeInOutPanelFragment);
        var6.addDestination(var10035);
        Destination var10033 = var2.createDestination();
        com.huawei.hms.audioeditor.ui.p.a.a(var10033, id.audioVolumeSpeedPanelFragment, AudioVolumeSpeedPanelFragment.class, "AudioVolumeSpeedPanelFragment");
        var10033.putAction(id.action_audioEditMenuFragment_to_audioVolumeSpeedPanelFragment, id.audioVolumeSpeedPanelFragment);
        var6.addDestination(var10033);
        Destination var10031 = var2.createDestination();
        com.huawei.hms.audioeditor.ui.p.a.a(var10031, id.audioSoundFiledPanelFragment, AudioSoundGroundPanelFragment.class, "AudioSoundFiledPanelFragment");
        var10031.putAction(id.action_audioEditMenuFragment_to_audioSoundFiledPanelFragment, id.audioSoundFiledPanelFragment);
        var6.addDestination(var10031);
        Destination var10029 = var2.createDestination();
        com.huawei.hms.audioeditor.ui.p.a.a(var10029, id.audioMusicStylePanelFragment, AudioMusicStylePanelFragment.class, "AudioMusicStylePanelFragment");
        var10029.putAction(id.action_audioEditMenuFragment_to_audioMusicStylePanelFragment, id.audioMusicStylePanelFragment);
        var6.addDestination(var10029);
        Destination var10027 = var2.createDestination();
        com.huawei.hms.audioeditor.ui.p.a.a(var10027, id.audioBalancePanelFragment, AudioBalancePanelFragment.class, "audioBalancePanelFragment");
        var10027.putAction(id.action_audioEditMenuFragment_to_audioBalancePanelFragment, id.audioBalancePanelFragment);
        var6.addDestination(var10027);
        Destination var10025 = var2.createDestination();
        com.huawei.hms.audioeditor.ui.p.a.a(var10025, id.audioVoiceChangeFragment, AudioVoiceChangeFragment.class, "audioVoiceChangePanelFragment");
        var10025.putAction(id.action_audioEditMenuFragment_to_audioVoiceChangeFragment, id.audioVoiceChangeFragment);
        var6.addDestination(var10025);
        Destination var10023 = var2.createDestination();
        com.huawei.hms.audioeditor.ui.p.a.a(var10023, id.audioCopyPanelFragment, AudioCopyPanelFragment.class, "audioCopyPanelFragment");
        var10023.putAction(id.action_audioEditMenuFragment_to_audioCopyPanelFragment, id.audioCopyPanelFragment);
        var6.addDestination(var10023);
        Destination var10021 = var2.createDestination();
        com.huawei.hms.audioeditor.ui.p.a.a(var10021, id.audioVolumePanelFragment, AudioVolumePanelFragment.class, "audioVolumePanelFragment");
        var10021.putAction(id.action_audioEditMenuFragment_to_audioVolumePanelFragment, id.audioVolumePanelFragment);
        var6.addDestination(var10021);
        Destination var10019 = var2.createDestination();
        com.huawei.hms.audioeditor.ui.p.a.a(var10019, id.audioSpaceRenderPanelFragment, AudioSpaceRenderPanelFragment.class, "audioSpaceRenderPanelFragment");
        var10019.putAction(id.action_audioEditMenuFragment_to_audioSpaceRenderPanelFragment, id.audioSpaceRenderPanelFragment);
        var6.addDestination(var10019);
        Destination var10017 = var2.createDestination();
        com.huawei.hms.audioeditor.ui.p.a.a(var10017, id.audioTextToSpeechPanelFragment, AudioTextToSpeechPanelFragment.class, "audioTextToSpeechPanelFragment");
        var10017.putAction(id.action_audioEditMenuFragment_to_audioTextToSpeechPanelFragment, id.audioTextToSpeechPanelFragment);
        var6.addDestination(var10017);
        Destination var10015 = var2.createDestination();
        com.huawei.hms.audioeditor.ui.p.a.a(var10015, id.audioSoundSeparationPanelFragment, AudioSoundSeparationPanelFragment.class, "audioSoundSeparationPanelFragment");
        var10015.putAction(id.action_audioEditMenuFragment_to_audioSoundSeparationPanelFragment, id.audioSoundSeparationPanelFragment);
        var6.addDestination(var10015);
        Destination var10013 = var2.createDestination();
        com.huawei.hms.audioeditor.ui.p.a.a(var10013, id.audioEnvironmentPanelFragment, AudioEnvironmentPanelFragment.class, "audioEnvironmentPanelFragment");
        var10013.putAction(id.action_audioEditMenuFragment_to_audioEnvironmentPanelFragment, id.audioEnvironmentPanelFragment);
        var6.addDestination(var10013);
        Destination var10011 = var2.createDestination();
        com.huawei.hms.audioeditor.ui.p.a.a(var10011, id.audioAccompanimentSeparation, AudioAccompanimentSeparationPanelFragment.class, "audioAccompanimentSeparationPanelFragment");
        var10011.putAction(id.action_audioEditMenuFragment_to_audioAccompanimentSeparation, id.audioAccompanimentSeparation);
        var6.addDestination(var10011);
        Destination var10009 = var2.createDestination();
        com.huawei.hms.audioeditor.ui.p.a.a(var10009, id.soundEffectPanelFragment, SoundEffectPanelFragment.class, "soundEffectPanelFragment");
        var10009.putAction(id.action_audioEditMenuFragment_to_soundEffectPanelFragment, id.soundEffectPanelFragment);
        var6.addDestination(var10009);
        Destination var10007 = var2.createDestination();
        com.huawei.hms.audioeditor.ui.p.a.a(var10007, id.audioMaterialPanelFragment, AudioMaterialPanelFragment.class, "AudioMaterialPanelFragment");
        var10007.putAction(id.action_audioEditMenuFragment_to_audioMaterialPanelFragment, id.audioMaterialPanelFragment);
        var6.addDestination(var10007);
        Destination var10005 = var2.createDestination();
        com.huawei.hms.audioeditor.ui.p.a.a(var10005, id.audioMaterialSearchPanelFragment, AudioMaterialSearchPanelFragment.class, "audioMaterialSearchPanelFragment");
        var10005.putAction(id.action_audioEditMenuFragment_to_audioMaterialSearchPanelFragment, id.audioMaterialSearchPanelFragment);
        var10003.addDestination(var10005);
        var10003.setStartDestination(id.audioEditMenuFragment);
        var10002.o.setGraph(var6);
        var10001.h();
        var10000.g();
    }

    protected void onActivityResult(int var1, int var2, @Nullable Intent var3) {
        super.onActivityResult(var1, var2, var3);
        if (1002 == var1) {
            if (var2 == 200) {
                this.b(var3);
            } else {
                this.b((Intent) null);
            }
        }

    }

    public boolean dispatchTouchEvent(MotionEvent var1) {
        return this.getWindow().superDispatchTouchEvent(var1) || super.dispatchTouchEvent(var1);
    }

    public void a() {
        label31:
        {
            AudioClipsActivity var10000;
            Intent var10002;
            Intent var4;
            try {
                var10000 = this;
                var4 = new Intent();
                var10002 = var4;
//                var4.<init>();
            } catch (ActivityNotFoundException var3) {
                break label31;
            }

            String var10003 = "com.huawei.hms.audioeditor.chooseaudio";

            try {
                var10002.setAction(var10003);
            } catch (ActivityNotFoundException var2) {
                break label31;
            }

            short var5 = 1002;

            try {
                var10000.startActivityForResult(var4, var5);
                return;
            } catch (ActivityNotFoundException var1) {
//
            }
        }

        SmartLog.e("AudioClipsFragment", "can't find the choose audio activity");
    }

    public void d() {
        if (!this.A) {
            this.A = true;
            this.k.show();
        }

    }

    public void b() {
        this.A = false;
        this.k.hide();
        AlertDialog var1;
        if ((var1 = this.l) != null) {
            var1.cancel();
            this.l = null;
        }

    }

    public void onSaveInstanceState(@NonNull Bundle var1) {
        super.onSaveInstanceState(var1);
        AudioClipsActivity var10000 = this;
        AudioClipsActivity var10003 = this;
        long var2 = this.p;
        var1.putLong("mCurrentTime", var2);
        var1.putString("draftId", var10003.f.getProjectId());
        var10000.onSaveInstanceState(var1);
    }

    protected void onRestoreInstanceState(@NonNull Bundle var1) {
        super.onRestoreInstanceState(var1);
        this.u = var1.getString("draftId");
        this.h();
    }

    public void onBackPressed() {
        if (this.o.getCurrentDestination() == null) {
            this.finish();
        } else if (this.o.getCurrentDestination().getId() == id.audioEditMenuFragment && this.menuViewModel.ldMenuType.getValue() != MenuHelper.MenuType.a) {
            this.a(0);
            this.editPreviewViewModel.setLdUuid("");
        } else if (this.o.getCurrentDestination().getId() == id.audioMaterialSearchPanelFragment) {
            this.o.navigate(id.audioMaterialPanelFragment);
        } else if (this.o.getCurrentDestination().getLabel().toString().contains("Panel")) {
            if (this.editPreviewViewModel.r() != null && !(Boolean) this.editPreviewViewModel.r().getValue()) {
                this.o.navigate(id.audioEditMenuFragment);
            }

        } else {
            if (this.f != null) {
                ConfirmDialog var1;
                var1 = new ConfirmDialog(this.getResources().getString(string.select_to_export), (var1x) -> {
                    if (var1x) {
                        this.startActivity(new Intent(this, AudioExportActivity.class));
                    } else {
                        this.k();
                    }

                });
                if (!this.w && this.x) {
                    var1.setCancelable(true);
                    var1.show(this.getSupportFragmentManager(), "confirmDialog");
                } else {
                    this.k();
                }
            }

        }
    }

    public void onDestroy() {
        super.onDestroy();
    }

    public void c() {
        this.f.pauseTimeLine();
        this.clipViewModel.a(false);
    }

    public void a(long var1) {
        SmartLog.i("AudioClipsFragment", "seekTimeLine:" + var1);
        if (var1 < this.r) {
            this.n.removeCallbacksAndMessages((Object) null);
            this.q = System.currentTimeMillis();
//            this.f.seekTimeLine(var1, new j(this));
            this.r = var1;
        } else {
            long var3;
            if ((var3 = System.currentTimeMillis()) - this.q >= 10L) {
                var3 = 0L;
            } else {
                this.n.removeCallbacksAndMessages((Object) null);
                var3 -= this.q;
            }

            this.r = var1;
            this.n.postDelayed(() -> {
                this.q = System.currentTimeMillis();
//                this.f.seekTimeLine(var1, new j(this));
            }, var3);
        }

        this.clipViewModel.b(var1);
    }

    public void a(int var1) {
        if (this.o.getCurrentDestination() != null && this.o.getCurrentDestination().getId() != id.audioEditMenuFragment) {
            if ((Boolean) this.editPreviewViewModel.r().getValue()) {
                return;
            }

            this.o.navigate(id.audioEditMenuFragment);
        }

        if (var1 != -1) {
            if (var1 == 1 && !TextUtils.isEmpty((CharSequence) this.editPreviewViewModel.getLdUuid().getValue())) {
                this.menuViewModel.ldMenuType.postValue(MenuHelper.MenuType.b);
            } else if (var1 == 2 && !TextUtils.isEmpty((CharSequence) this.editPreviewViewModel.getLdUuid().getValue())) {
                this.menuViewModel.ldMenuType.postValue(MenuHelper.MenuType.c);
            } else if (var1 == 3 && !TextUtils.isEmpty((CharSequence) this.editPreviewViewModel.getLdUuid().getValue())) {
                this.menuViewModel.ldMenuType.postValue(MenuHelper.MenuType.d);
            } else {
                this.menuViewModel.ldMenuType.postValue(MenuHelper.MenuType.a);
            }

        }
    }

    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        if (this.d != null) {
            this.getSupportFragmentManager().beginTransaction().remove(this.d).commitAllowingStateLoss();
        }

        NavHostFragment var1;
        if ((var1 = (NavHostFragment) this.getSupportFragmentManager().findFragmentById(id.audio_menu_item_fragment)) != null) {
            this.getSupportFragmentManager().beginTransaction().remove(var1).commitAllowingStateLoss();
        }

    }

    public void onPause() {
        super.onPause();
        ArrayList var1;
        ArrayList var10001 = var1 = new ArrayList<>();
//        var10001.<init>();
        this.a((List) var10001);
        if (var1.size() > 0) {
            this.f.saveProject();
        }

    }
}
